package cn.itcast.wanxinp2p.account.controller;

import cn.itcast.wanxinp2p.account.service.AccountService;
import cn.itcast.wanxinp2p.api.account.AccountAPI;
import cn.itcast.wanxinp2p.api.account.model.AccountDTO;
import cn.itcast.wanxinp2p.api.account.model.AccountLoginDTO;
import cn.itcast.wanxinp2p.api.account.model.AccountRegisterDTO;
import cn.itcast.wanxinp2p.common.domain.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Description
 * @Author Administrator
 * @Date 2023/8/25 15:07
 **/
@RestController

@Api(value = "统一账户服务")
public class AccountConroller implements AccountAPI {
    @Autowired
    private AccountService accountService;
    @ApiOperation(value = "测试")
    @GetMapping("/he")
    public String he() {
        return "hahahahha";
    }

    //    获取短信验证码
    @ApiOperation(value = "短信验证码发送")
    @GetMapping("/sms/{mobile}")
    @Override
    public RestResponse getSMSCode(@PathVariable String mobile) {
        return accountService.getSMSCode(mobile);
    }
    // * 校验手机号和验证码     * @param mobile 手机号
    //   * @param key  校验标识
    //   * @param code 验证码
    @ApiOperation(value = "校验手机号和验证码")
    @GetMapping("mobiles/{mobile}/key/{key}/code/{code}")
    @Override
    public RestResponse<Integer> checkMobile(@PathVariable String mobile, @PathVariable String key,@PathVariable String code) {

        return accountService.checkMobile(mobile, key, code);
    }

    //  * 注册 保存信息
    @PostMapping("/l/accounts")
    @Override
    public RestResponse<AccountDTO> register(AccountRegisterDTO accountRegisterDTO) {
        return accountService.register(accountRegisterDTO);
    }

    //   * 用户登录
//     * @param accountLoginDTO 封装用户登录信息
    @PostMapping(value = "/l/accounts/session")
    @Override
    public RestResponse<AccountDTO> login(@RequestBody AccountLoginDTO accountLoginDTO) {
        return RestResponse.success(accountService.login(accountLoginDTO));
    }
}
